package com.ava.avamedia.account;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.ava.avamedia.MainActivity;
import com.ava.avamedia.R;
import com.ava.avamedia.adapter.AccountAdapter;
import com.ava.avamedia.model.Account;
import com.ava.avamedia.util.Constants;
import com.congnt.library.common.ConfigManager;

public class AccountActivity extends Activity{
	private ConfigManager config;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_region);
		config = new ConfigManager(this, true);
		
//		registerReceiver(LOGOUT_Reciver, new IntentFilter(Constants.FINSIH_ACTION));
		ListView listView = (ListView) findViewById(R.id.activity_region_list_view);
		AccountAdapter adapter= new AccountAdapter(this, getListAccount());
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if (arg2 == 1 ) {
					Intent intent = new Intent();
					intent.setClass(AccountActivity.this, PaymentActivity.class);
					intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
					startActivity(intent);
				}
				if (arg2 == 5) {
					config.putBoolean(Constants.REMEMBER,false);
					Intent i=new Intent(Constants.FINSIH_ACTION);
	        		i.putExtra(Constants.FINISH, Constants.ACTION_LOGOUT);
	        		sendBroadcast(i);
					Intent intent = new Intent();
					intent.setClass(AccountActivity.this, MainActivity.class);
					intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
					startActivity(intent);
					finish();
				}
			}
		});
	}
	public ArrayList<Account> getListAccount(){
		ArrayList<Account> arrayList = new ArrayList<Account>();
		arrayList.add(new Account("Thông tin tài khoản", "Xem chi tiết tài khoản của bạn",false));
		arrayList.add(new Account("Nạp tiền tài khoản", "Nạp Vàng cho AVAMedia",true));
		arrayList.add(new Account("Lịch sử giao dịch", "Xem nhật ký các giao dịch gần nhất",false));
		arrayList.add(new Account("Tặng vàng", "Tặng vàng cho tài khoản khác",false));
		arrayList.add(new Account("Hòm thư góp ý", "",true));
		arrayList.add(new Account("Đăng xuất", "",true));
		return arrayList;
		
	}
//	private BroadcastReceiver LOGOUT_Reciver = new BroadcastReceiver() {
//
//		@Override
//		public void onReceive(Context arg0, Intent arg1) {
//			String action_finish = arg1.getStringExtra(Constants.FINISH);
//
//			if (action_finish.equalsIgnoreCase(Constants.ACTION_LOGOUT)) {
//				finish();
//				// this line unregister the receiver,so that i run only one time
//				// and when next time logout is clicked then again it called
//				unregisterReceiver(LOGOUT_Reciver);
//			}
//
//		}
//	};
}
